<template>
    <div class="safetyStatisticsContent">
        <img src="@/assets/bigScreen/icons/left/moduls_bg.png" alt="">
        <div class="titles_moduls">
            <img src="@/assets/bigScreen/icons/left/aqtj.png" alt="">
            安全统计
        </div>
        <div class="right_button" @click="isDropdownVisible = !isDropdownVisible">
            {{ ids == 1 ? '问题等级' : ids == 2 ? '问题类型' : '问题状态' }}
            <div class="downs"></div>
        </div>


        <transition enter-active-class="animate__animated animate__fadeInRight"
            leave-active-class="animate__animated animate__fadeOutRight" appear>
            <div class="dropdown" v-if="isDropdownVisible" @mouseleave="isDropdownVisible = false">
                <div class="dropdown-item" @click="changeTab(1)">问题等级</div>
                <div class="dropdown-item" @click="changeTab(2)">问题类型</div>
                <div class="dropdown-item" @click="changeTab(3)">问题状态</div>
            </div>
        </transition>

        <div class="num">数量</div>
        <div class="echarts_box">
            <lineCharts v-if="isFlag" :leftEchartsData="leftEchartsData" />
        </div>
    </div>
</template>

<script>
import lineCharts from "../../components/echarts/index.vue";
import { getSafetyStatistics } from "@/api/bigScreen/home.js";

export default {

    components: {
        lineCharts
    },
    data() {
        return {
            leftEchartsData: {
                dataX: ["02-18", "02-19", "02-20", "02-21", "02-22", "02-23", "02-23", "02-25"],
                dataY: ["20", "65", "115", "245", "323", "30", "45", "425"],
                dataY2: ["110", "50", "425", "25", "113", "110", "140", "45"],
                legendData: ['一般', '严重']
            },
            ids: 1,
            isDropdownVisible: false,
            isFlag: false,

        };
    },
    mounted() {
        this.getData()
    },
    methods: {
        getData() {
            getSafetyStatistics(1).then(res => {
                if (res.code == 200 && res.data) {
                    this.leftEchartsData.dataX = []
                    this.leftEchartsData.dataY = []
                    this.leftEchartsData.dataY2 = []
                    res.data.forEach((item, index) => {
                        this.leftEchartsData.dataX.push(res.data[index].date)
                        this.leftEchartsData.dataY.push(res.data[index].ordinaryTotal)
                        this.leftEchartsData.dataY2.push(res.data[index].seriousTotal)
                    })
                    this.isFlag = true
                }
            })
            this.isFlag = true
        },
        changeTab(i) {
            this.ids = i
            this.isDropdownVisible = false
            this.isFlag = false
            this.leftEchartsData = {
                dataX: ["02-18", "02-19", "02-20", "02-21", "02-22", "02-23", "02-23", "02-25"],
                dataY: ["20", "65", "115", "245", "323", "30", "45", "425"],
                dataY2: ["110", "50", "425", "25", "113", "110", "140", "45"],
                legendData: ['一般', '严重']
            }
            switch (i) {
                case 1:
                    this.leftEchartsData.legendData = ['一般', '严重']
                    break;
                case 2:
                    this.leftEchartsData.legendData = ['操作行为', '设备设施']
                    break;
                case 3:
                    this.leftEchartsData.legendData = ['已处理', '待处理']
                    break;
            }

            this.getData(i)
        }
    },
};
</script>

<style scoped lang="scss">
@font-face {
    font-family: 'kk';
    src: url('../../../../../assets/font/kuaikanshijieti-Regular.ttf');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'al';
    src: url('../../../../../assets/font/Alibaba-PuHuiTi-Bold_0.ttf');
    font-weight: normal;
    font-style: normal;
}

.safetyStatisticsContent {
    width: 100%;
    position: relative;
    margin: 2.5% 0;

    .animate__animated {
        --animate-duration: .5s;
        --animate-delay: 0s;
    }

    img {
        width: 100%;
    }

    .titles_moduls {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        position: absolute;
        top: 3%;
        left: 1.5%;

        img {
            width: 1.2vw;
            margin-right: 0.5208vw;
        }


        font-size: 0.8333vw;
        font-weight: 400;
        letter-spacing: 0.0208vw;
        font-family: kk;
        color: transparent;
        background-image: linear-gradient(180deg, rgba(153, 253, 255, 1) 0%, rgba(13, 110, 255, 1) 100%);
        -webkit-background-clip: text;
        background-clip: text;

    }

    .right_button {
        position: absolute;
        cursor: pointer;
        right: 2%;
        top: 5%;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        font-size: 0.7292vw;
        font-weight: 400;
        letter-spacing: 0.4px;
        font-family: kk;
        color: transparent;
        background-image: linear-gradient(180deg, rgba(153, 253, 255, 1) 0%, rgba(13, 110, 255, 1) 100%);
        -webkit-background-clip: text;
        background-clip: text;


        .downs {
            width: 0.5729vw;
            height: 0.4167vw;
            background: linear-gradient(to top, rgba(153, 253, 255, 1) 0%, rgba(13, 110, 255, 1) 100%);
            margin-left: 0.4167vw;
            clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
        }
    }

    .dropdown {
        position: absolute;
        right: 0;
        top: 15%;
        width: 4.5vw;
        background: rgba(13, 31, 51, 0.85);
        border-radius: 0.4167vw;
        z-index: 11;
        box-shadow: 0 0.2083vw 0.4167vw rgba(0, 0, 0, 0.2);
        border: 1px solid rgba(0, 255, 240, 1);
        // border-image: linear-gradient(to bottom, rgba(0, 155, 254, 1), rgba(0, 255, 240, 1)) 1;


        &-item {
            padding: 0.425vw;
            font-size: 0.7292vw;
            color: #fff;
            cursor: pointer;

            &:hover {
                background: rgba(255, 255, 255, 0.1);
            }
        }
    }

    .echarts_box {
        width: 96%;
        position: absolute;
        bottom: 0;
        left: 2%;
        height: 11.9792vw;
        margin: 0 auto;
    }

    .num {
        font-size: .655vw;
        font-weight: 400;
        color: rgba(217, 240, 255, 1);
        position: absolute;
        left: 2%;
        top: 17%;
    }
}
</style>